<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改课程</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            padding: 20px;
        }

        .header {
            text-align: center;
            padding: 30px 0;
            color: #333;
        }

        .header h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
        }

        .form-container {
            background: white;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            padding: 30px;
            transition: all 0.3s ease;
        }

        .form-container:hover {
            box-shadow: 0 15px 40px rgba(0,0,0,0.15);
        }

        .form-title {
            text-align: center;
            margin-bottom: 30px;
            color: #333;
            font-size: 1.8rem;
        }

        .form-group {
            margin-bottom: 25px;
        }

        .form-group label {
            display: block;
            margin-bottom: 10px;
            font-weight: 600;
            color: #555;
            font-size: 1.1rem;
        }

        .form-group input,
        .form-group textarea,
        .form-group select {
            width: 100%;
            padding: 15px;
            border: 2px solid #e1e1e1;
            border-radius: 10px;
            font-size: 16px;
            transition: all 0.3s ease;
            box-sizing: border-box;
        }

        .form-group input:focus,
        .form-group textarea:focus,
        .form-group select:focus {
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
            outline: none;
        }

        .form-group textarea {
            height: 120px;
            resize: vertical;
        }

        .form-row {
            display: flex;
            gap: 20px;
        }

        .form-row .form-group {
            flex: 1;
        }

        .form-buttons {
            display: flex;
            gap: 15px;
            justify-content: flex-end;
            margin-top: 30px;
        }

        .btn {
            padding: 12px 25px;
            border: none;
            border-radius: 10px;
            cursor: pointer;
            font-size: 16px;
            font-weight: 600;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .btn-primary {
            background: linear-gradient(135deg, #2196F3 0%, #0b7dda 100%);
            color: white;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(33, 150, 243, 0.4);
        }

        .btn-secondary {
            background: linear-gradient(135deg, #9E9E9E 0%, #616161 100%);
            color: white;
        }

        .btn-secondary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(158, 158, 158, 0.4);
        }

        @media (max-width: 768px) {
            .form-row {
                flex-direction: column;
                gap: 0;
            }
            
            .header h1 {
                font-size: 2rem;
            }
        }
    </style>
</head>
<body>
    <div class="header">
        <h1><i class="fas fa-book"></i> 课程管理系统</h1>
        <p>哈尔滨信息工程学院 - 修改课程</p>
    </div>

    <div class="container">
        <div class="form-container">
            <h2 class="form-title"><i class="fas fa-edit"></i> 修改课程信息</h2>
            
            <form id="editCourseForm">
                <input type="hidden" th:value="${course.id}" name="id">
                
                <div class="form-group">
                    <label for="courseName"><i class="fas fa-book"></i> 课程名称</label>
                    <input type="text" id="courseName" th:value="${course.cname}" name="cname" placeholder="请输入课程名称" required>
                </div>

                <div class="form-group">
                    <label for="courseDescription"><i class="fas fa-align-left"></i> 课程简介</label>
                    <textarea id="courseDescription" name="mark" th:text="${course.mark}" placeholder="请输入课程简介" required></textarea>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <label for="teacherName"><i class="fas fa-chalkboard-teacher"></i> 任课教师</label>
                        <input type="text" id="teacherName" name="tea" th:value="${course.tea}" placeholder="请输入任课教师姓名" required>
                    </div>
                    
                    <div class="form-group">
                        <label for="courseCategory"><i class="fas fa-tags"></i> 课程分类</label>
                        <select id="courseCategory" name="category">
                            <option value="">请选择分类</option>
                            <option value="必修课" th:selected="${course.category == '必修课'}">必修课</option>
                            <option value="选修课" th:selected="${course.category == '选修课'}">选修课</option>
                            <option value="实践课" th:selected="${course.category == '实践课'}">实践课</option>
                            <option value="实验课" th:selected="${course.category == '实验课'}">实验课</option>
                            <option value="专业课" th:selected="${course.category == '专业课'}">专业课</option>
                            <option value="基础课" th:selected="${course.category == '基础课'}">基础课</option>
                        </select>
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <label for="courseCredit"><i class="fas fa-graduation-cap"></i> 学分</label>
                        <input type="number" id="courseCredit" name="credit" th:value="${course.credit}" min="1" max="10" placeholder="请输入学分">
                    </div>
                    
                    <div class="form-group">
                        <label for="courseSemester"><i class="fas fa-calendar-alt"></i> 学期</label>
                        <select id="courseSemester" name="semester">
                            <option value="">请选择学期</option>
                            <option value="春季学期" th:selected="${course.semester == '春季学期'}">春季学期</option>
                            <option value="秋季学期" th:selected="${course.semester == '秋季学期'}">秋季学期</option>
                            <option value="夏季学期" th:selected="${course.semester == '夏季学期'}">夏季学期</option>
                            <option value="冬季学期" th:selected="${course.semester == '冬季学期'}">冬季学期</option>
                        </select>
                    </div>
                </div>

                <div class="form-buttons">
                    <button type="button" class="btn btn-secondary" onclick="cancelEdit()">
                        <i class="fas fa-times"></i> 取消
                    </button>
                    <button type="button" class="btn btn-primary" onclick="courseEdit()">
                        <i class="fas fa-save"></i> 保存修改
                    </button>
                </div>
            </form>
        </div>
    </div>

    <script src="/js/jquery.min.js"></script>
    <script>
        // 提交表单
        function courseEdit() {
            var courseName = $("#courseName").val().trim();
            var courseDescription = $("#courseDescription").val().trim();
            var teacherName = $("#teacherName").val().trim();
            
            if (!courseName || !courseDescription || !teacherName) {
                alert("请填写必填项：课程名称、简介和任课教师");
                return;
            }
            
            $.ajax({
                type: "POST",
                url: "/course/save",
                data: $("#editCourseForm").serialize(),
                success: function (data) {
                    if (data == 1) {
                        alert("课程修改成功");
                        window.location.href = "/course/view";
                    } else {
                        alert("修改失败，请重试");
                    }
                },
                error: function() {
                    alert("请求失败，请检查网络连接");
                }
            });
        }
        
        function cancelEdit() {
            if (confirm("确定要取消修改吗？")) {
                window.location.href = "/course/view";
            }
        }
    </script>
</body>
</html>